Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@types/keyv

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/keyv

TypeScript definitions for keyv

  • 3.1.4
  • ts3.9
  • ts4.0
  • ts4.1
  • ts4.2
  • ts4.3
  • ts4.4
  • ts4.5
  • ts4.6
  • ts4.7
  • ts4.8
  • ts4.9
  • npm
  • Socket score

Version published
Weekly downloads
8.8M
increased by7.29%
Maintainers
1
Weekly downloads
 
Created

What is @types/keyv?

The @types/keyv package provides TypeScript type definitions for Keyv, a simple key-value storage with support for multiple backends. It allows TypeScript users to work with Keyv more effectively by offering type checking and IntelliSense features in their IDEs. Keyv itself is a simple, promisified key-value storage solution that supports various storage backends like Redis, MongoDB, SQLite, and more.

What are @types/keyv's main functionalities?

Basic Key-Value Operations

This feature demonstrates basic CRUD operations: setting, getting, deleting, and clearing key-value pairs. It's the core functionality of Keyv, allowing simple data storage and retrieval.

{"import Keyv from 'keyv';
const keyv = new Keyv();

// Set a value
await keyv.set('foo', 'bar');

// Get a value
const value = await keyv.get('foo');
console.log(value); // 'bar'

// Delete a value
await keyv.delete('foo');

// Clear all keys
await keyv.clear();"}

Using Namespaces

This feature shows how to use namespaces to separate different types of data within the same database or storage backend. It's useful for organizing data and preventing key collisions.

{"import Keyv from 'keyv';
const users = new Keyv('sqlite://path/to/database.sqlite', { namespace: 'users' });
const cache = new Keyv('sqlite://path/to/database.sqlite', { namespace: 'cache' });

// Set and get values in the 'users' namespace
await users.set('john', { age: 30 });
const john = await users.get('john');
console.log(john); // { age: 30 }

// The 'cache' namespace remains unaffected
const cacheValue = await cache.get('john');
console.log(cacheValue); // undefined"}

Custom Storage Backend

This feature illustrates how to use a custom storage backend, in this case, Redis, with Keyv. It demonstrates Keyv's flexibility in supporting different storage solutions.

{"import Keyv from 'keyv';
import KeyvRedis from '@keyv/redis';
const keyv = new Keyv({ store: new KeyvRedis('redis://user:pass@localhost:6379') });

// Now Keyv will use Redis as its storage backend
await keyv.set('hello', 'world');
const value = await keyv.get('hello');
console.log(value); // 'world'"}

Other packages similar to @types/keyv

FAQs

Package last updated on 17 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc